﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IService.Business;
using IService.Model;
using IService.DataDLL.Utility;

namespace IService.Admin.Pages
{
    public partial class PreviewActivity : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                CheckIntType(ActivityId);
            }
        }

        protected void CheckIntType(string param)
        {
            if (!ParamHandler.IsLegalForInt(param))
            {
                Response.Redirect(StringUtil.GetAppConfigString("AdminParamErrorPage"));
            }
        }

        protected Dictionary<string, string> GetActivityContent
        {
            get
            {
                Dictionary<string, string> result = ContentDetail;
                if (result == null)
                {
                    result = new Dictionary<string, string>();
                    int newsid = int.Parse(ActivityId);
                    Activity activity = DTVBusiness.ActivityManager.GetActivityById(newsid);
                    result.Add("Title", activity.Title);
                    result.Add("Details", activity.Details);
                    result.Add("PublishMan", GetUserNameById(activity.CreateUserId));
                    result.Add("CreateTime", activity.CreateTime.ToString());
                    result.Add("Image", activity.Image);
                    ContentDetail = result;
                }
                else
                {
                    //页面不存在
                }
                return result;
            }
        }

        protected string GetUserNameById(Int64 userId)
        {
            DTVAdmin user = DTVBusiness.AdminManager.GetUserById((int)userId);
            if (user != null)
            {
                return user.Username;
            }
            return string.Empty;
        }

        protected string GetTypeNameByValue(int parentId)
        {
			DTVType type = DTVBusiness.TypeManager.GetTypeById(parentId);
            if (type != null)
            {
                return type.TypeName;
            }
            return string.Empty;
        }

        protected string ActivityId
        {
            get
            {
                return base.Request["activityId"];
            }
        }

        protected Dictionary<string, string> ContentDetail
        {
            get
            {
                return (this.ViewState["contentDetail"] as Dictionary<string, string>);
            }
            set
            {
                this.ViewState["contentDetail"] = value;
            }
        }
    }
}